/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.mybugshaker.flow.email.screenshot;

import io.reactivex.Observable;
import ohos.aafwk.ability.Ability;
import ohos.agp.utils.Rect;
import ohos.agp.window.service.WindowManager;
import ohos.media.image.PixelMap;

public final class  PixelMapScreenShot {
    private PixelMapScreenShot() {
    }

    private static final int EIGHTEEN = 80;

    public static Observable<PixelMap> create(Ability ability) {
        return Observable.create(subscriber->{
            final PixelMap screenPixelMap = getCapterScreen();
            subscriber.onNext(screenPixelMap);
            subscriber.onComplete();
        });
    }
// TODO 系统不支持第三方应用截图
    private static PixelMap getCapterScreen(){
        WindowManager windowManager = WindowManager.getInstance();
        Rect rect = new Rect(0,0,0,0);
        PixelMap pixelMap;
        pixelMap = windowManager.captureScreen(rect,EIGHTEEN,EIGHTEEN,0);
        return  pixelMap;
    }
}
